<template>
	<view>
		<map id="myMap" style="width: 100%; height: 300px;" :latitude="latitude" :longitude="longitude" show-location></map>

		<button @tap="getCenterLocation" class="page-body-button" type="primary">获取位置</button>
		<button @tap="moveToLocation" class="page-body-button" type="primary">移动位置</button>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				mapCtx: null,
				latitude: 40.041043,
				longitude: 116.275073
			}
		},
		onReady() {
			this.mapCtx = wx.createMapContext('myMap')
		},
		methods: {
			getCenterLocation() {
				  this.mapCtx.getCenterLocation({
				      success: function(res){
				        console.log(res.longitude)
				        console.log(res.latitude)
				      }
				    })
			},
			moveToLocation() {
				this.mapCtx.moveToLocation()
			}
		}
	}
</script>

<style>

</style>
